import {defaultStyle} from "@/svgutil/default-style";
import * as Dt from '@/svgutil/draw-type';
//import {findObjectValue, findText} from "@/svgutil/comm-method";
export const defineData = function (values) {
    console.log(values.length);
    let pipeSize = 4;
    return {
        translate: [50.5, 50.5],
        style: {...defaultStyle},
        children: [
            leftPipe(pipeSize),
            centerPipe(),
            ...bluePlant(),
            ...leftRect(pipeSize),
            topPipe(),
            rightPipe(),
            ...container(530, 84)
        ]
    }
}
function rightPipe(){
    let rightPipe = Dt.path(null,{stroke:'rgb(67,155,80)',fill:'',strokeWidth: 5});
    rightPipe.moveto(790,184).linetoRy(120).linetoRx(440).linetoRy(144);
    for(let i=0;i<3;i++){
        rightPipe.moveto(1230,444 - i * 50).linetoRx(-100).linetoRy(30).linetoRx(-40);
    }
    rightPipe.movetoRxy(0,-4).linetoRy(120).linetoRx(-150).linetoRy(150)
        .linetoRx(70).linetoRy(-70).linetoRx(220);
    let softWaterTank = createSoftWaterTank(956,580,'2176');
    //右管上面的3个读数
    let label1 = createLabel(940,250,99,'%');
    let label2 = createLabel(1030,250,'25.0','m³/h');
    let label3 = createLabel(1120,250,0.66,'MPa');
    rightPipe.children = [softWaterTank,label1,label2,label3];
    //右管上面的三个阀门的名称
    let text1 = Dt.text(970,322,'给水开度',{fill: '#0f0',fontSize: 11});
    let text2 = Dt.text(1060,322,'给水流量',{fill: '#fff',fontSize: 11});
    let text3 = Dt.text(1150,322,'给水压力',{fill: '#fff',fontSize: 11});
    rightPipe.children.push(text1,text2,text3);
    //右管中间三个水泵
    for(let i=1;i<4;i++){
        let textX= 1116;
        let textY = 336;
        let pumpText1 = Dt.text(textX,textY + i * 50,(4-i)+ '#',{fill: '#fff',fontSize: 11});
        let pumpText2 = Dt.text(textX + 80,textY + i * 50 - 30,'电动给水泵',{fill: '#fff',fontSize: 11});
        rightPipe.children.push(pumpText1,pumpText2);
    }


    return rightPipe;
}
function createSoftWaterTank(startX,startY,value){
    let w = 78;
    let h = 80;
    let softWaterTank = Dt.rect(startX, startY, w, h)
        .setRxy(140, 10)
        .setStyle({fill: 'url(#grad2)',stroke: 'rgb(52,46,46)',strokeWidth:1});
    let px = startX + 6,py = startY +10,pw = w-12,ph=h-20;
    let panel = Dt.rect(px,py, pw,ph,{fill:'rgb(7,30,11)',stroke:''});
    let text1 = Dt.text(px + 2 ,py + 24 ,value,{textAlign:'left',fill:'#fff',fontSize: 12});
    let text2 = Dt.text(px+pw - 2,py + 24,'MM',{textAlign:'right',fill:'#fff',fontSize: 10});
    let text3 = Dt.text(startX + w/2,startY + h + 16,'软水箱',{textAlign:'left',fontWeight: 600,fill:'#fff',fontSize: 11});
    softWaterTank.children = [panel,text1,text2,text3];
    return softWaterTank;
}
function topPipe(){
    let topPipe = Dt.path(null,{stroke: '#e10505',strokeWidth: 5,fill: ''})
        .moveto(730,84).linetoRy(-40).linetoRx(500)
        .movetoRxy(-380,0).linetoRy(-40).linetoRx(190);
    let topText1 = createLabel(760,14,'0.0','t/h');

    topPipe.children=[topText1];
    return topPipe;
}

function container(startX, startY) {
    let w = 400;
    let h = 100;
    let c = Dt.rect(startX, startY, w, h)
        .setRxy(40, 50)
        .setStyle({fill: 'url(#grad1)',stroke: 'rgb(120,105,105)',strokeWidth:2});
    let liqAmount1 = createLiq1(startX + 30, startY + 10, 16, 80, 60, '#0f0');
    let liqAmount2 = createLiq1(startX + w - 46, startY + 10, 16, 80, 60, '#0f0');
    //容器中间凹槽
    let x1 = startX + 54, y1 = startY + 4, x2 = startX + w - 54, y2 = y1;
    let x3 = x1 + 16, y3 = y1 + 10, x4 = x2 - 16, y4 = y3;
    let x5 = x1, y5 = startY + h - 4, x6 = x2, y6 = y5;
    let x7 = x3, y7 = y5 - 10, x8 = x4, y8 = y7;
    let aoCaoPath1 = Dt.path().setStyle({fill: 'rgb(165,100,100)',stroke: 'rgb(114,72,72)',strokeWidth:2});
    aoCaoPath1.moveto(x1,y1).lineto(x3,y3).lineto(x7,y7).lineto(x8,y8).lineto(x6,y6).lineto(x5,y5).closepath();
    let aoCaoPath2 = Dt.path().setStyle({fill: 'rgb(225,196,196)',stroke: 'rgb(120,105,105)',strokeWidth:2});
    aoCaoPath2.moveto(x1,y1).lineto(x3,y3).lineto(x4,y4).lineto(x8,y8).lineto(x6,y6).lineto(x2,y2).closepath();
    let panel = Dt.rect(x3,y3,x8-x3,y8-y3,{fill: '#000'});
    //面板文字：
    let text1 = createText(x3 +10,y3+ 20,'A侧','541');
    let text2 = createText(x4 -70,y3+ 20,'B侧',553);
    //let text3 = createText(x3 + 70,y3 - 20,'',0.47);
    let text3 = createLabel(x3 + 70,y3 +1,0.47,'MPa','#c90707');

    return [c, liqAmount1, liqAmount2,aoCaoPath1,aoCaoPath2,panel,text1,text2,text3];

}
function createLabel(x,y,value,unit,fill = '#000',fontColor = '#fff'){
    let rectText = Dt.rect(x,y,70,16).setStyle({fill: fill,stroke: ''});
    let text1 = Dt.text(x ,y+8,value,{textAlign:'left',fill:fontColor,fontSize: 12});
    let text2 = Dt.text(x + 70,y+8,unit,{textAlign:'right',fill:fontColor,fontSize: 12});
    rectText.children = [text1,text2];
    return rectText;
}
function createText(x,y,t1,t2){
    let textArray = [];
    let rectText = Dt.rect(x,y + 24,60,16).setStyle({fill: '#c90707'});
    let text1 = Dt.text(x + 14,y+32,t2,{fill:'#fff',fontSize: 12});
    textArray.push(text1);
    let text2;
    if(t1){
        text2 = Dt.text(x + 46,y+32,'mm',{fill:'#fff',fontSize: 12});
        let text3 = Dt.text(x + 28,y+10,t1,{fill:'#fff'});
        textArray.push(text2,text3);
    }else {
        text2 = Dt.text(x + 46,y+32,'MPa',{fill:'#fff',fontSize: 12});
        textArray.push(text2);
    }
    rectText.children = textArray;
    return rectText;
}
function createLiq1(x, y, w, h, a, aColor) {
    let bar = Dt.rect(x, y, w, h, {fill: '#000'});
    let barAmount = Dt.rect(x, y + (h - a), w, a, {fill: aColor});
    bar.children = [barAmount];
    return bar;
}

function bluePlant() {
    //let bluePlant = Dt.path().setStyle({strokeWidth: 14,stroke:'#02b2b2',fill: ''});
    //bluePlant.moveto(630,485).linetoRx(220);
    //bluePlant.moveto(630,365).linetoRx(220);
    let plantStyle = {strokeWidth: 1, stroke: '#000', fill: '#0ff'};
    let bluePlant1 = Dt.rect(626, 365, 220, 16, plantStyle).setRadius(10);
    let bluePlant2 = Dt.rect(626, 480, 220, 16, plantStyle).setRadius(10);

    let label1 = createLabel(510,360,0.41,'MPa');

    bluePlant1.children = [label1];
    return [bluePlant1, bluePlant2];
}

function centerPipe() {
    let centerPipe = Dt.path().setStyle({strokeWidth: 5, stroke: '#777702', fill: ''});
    centerPipe.moveto(440, 340).linetoY(674);
    for (let i = 0; i < 9; i++) {
        centerPipe.moveto(440, 345 + 40 * i).linetoRx(-200);
    }
    centerPipe.moveto(465, 380).linetoY(644);
    for (let i = 0; i < 4; i++) {
        centerPipe.moveto(465, 385 + 80 * i).linetoRx(-30);
    }
    centerPipe.moveto(440, 605).linetoX(710).linetoRy(-120);
    centerPipe.movetoRxy(30, 0).linetoRy(150).linetoX(465);
    centerPipe.moveto(710, 485).linetoRx(-40);
    for (let i = 0; i < 3; i++) {
        centerPipe.moveto(670 + i * 80, 485).linetoRy(-80).linetoRx(-30).linetoRy(-40);
    }
    centerPipe.moveto(710, 365).linetoY(184).moveto(740, 365).linetoY(184);

    //数值： 9个支管的数值
    let values = [48,45,48,45,48,45,48,43,50];
    centerPipe.children = [];
    for(let i=0;i<9;i++){
        let x = 290;
        if(i % 2 === 1){
            x += 50;
        }
        let y = 325 + 40 * i;
        let label = createLabel(x,y,values[i],'m³/h');
        centerPipe.children.push(label);
    }
    //数值：两个总管的数值：
    let total1 = createLabel(580,584,284,'m³/h');
    let total2 = createLabel(620,614,207,'m³/h');

    centerPipe.children.push(total1,total2);
    return centerPipe;
}

function leftPipe() {
    let leftPipe = Dt.path().setStyle({strokeWidth: 5, stroke: '#9b0202', fill: 'none'});
    leftPipe.moveto(0, 280).linetoRy(394);
    for (let i = 0; i < 9; i++) {
        leftPipe.moveto(0, 345 + 40 * i).linetoRx(34);
    }
    leftPipe.moveto(0, 284).lineto(650, 284).linetoRy(-100);
    return leftPipe;
}

function leftRect() {
    let textList = ['文字1', '文字2', '文字3', '文字4', '文字5', '文字6', '文字7', '文字8', '文字9']
    let rectArray = [];
    let width = 210;
    let height = 12;
    for (let i = 0; i < 9; i++) {
        let style;
        let fontStyle;
        if (i % 2 === 0) {
            style = {fill: '#ccc', strokeWidth: 2};
            fontStyle = {fill: '#000', textAlign: 'left', fontSize: 10};
        } else {
            style = {fill: '#00f', strokeWidth: 2};
            fontStyle = {fill: '#fff', textAlign: 'left', fontSize: 10}
        }
        let rect = Dt.rect(34, 340 + i * 40, width, height, style)
            .setText('--' + textList[i], fontStyle);
        rectArray.push(rect);
    }
    return rectArray;
}
